<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------
namespace app\portal\controller;

use cmf\controller\HomeBaseController;
use think\Db;
use think\Request;
use app\portal\model\MessageModel;

class IndexController extends HomeBaseController
{
    
    /**
     * 首页
     */
    public function index(){

        $message  = Db::name('message')->where('status', 1)->select();

        $shop  = Db::name('slide_item')->where('slide_id', 1)->select();
        $tim  = Db::name('slide_item')->where('slide_id', 2)->select();

        $this->assign('message',$message);
        $this->assign('shop',$shop);
        $this->assign('tim',$tim);
    	return $this->fetch(':join');
    }
    
    /**
     * 产品列表页
     */
    public function productlist(){
         
        $cate_id = $this->request->param('cate_id');
        if ($cate_id) {
            $where['cate_id'] = $cate_id;
        }
        $where['status'] = 1;
        $result = Db::name('product')->where($where)->order('update_time')->field('id,title,pic')->paginate(9);
        
        $cates  = Db::name('product_cate')->where('status', 1)->select();

        $this->assign('data', $result->items());
        $this->assign('page', $result->render());
        $this->assign('cates', $cates);

    	return $this->fetch(':productlist');
    }
    
    /**
     * 产品详情页
     */
    public function productdetail(){

        $id = $this->request->param('id');
        $data = Db::name('product')->find($id);

        $cates  = Db::name('product_cate')->where('status', 1)->select();

        $this->assign('cates', $cates);
        $this->assign('data', $data);

    	return $this->fetch(':productdetail');
    }
    
    /**
     * 加盟店列表
     */
    public function joinshow(){

        $result = Db::name('join')->where('status', 1)->order('update_time')->field('id,title,pic')->paginate(9);

        $this->assign('data', $result->items());
        $this->assign('page', $result->render());

    	return $this->fetch(':joinshow');
    }

    /**
     * 加盟详情
     */
    public function joindetail(){
        $id = $this->request->param('id');
        $data = Db::name('join')->find($id);
        $this->assign('data', $data);
    	return $this->fetch(':joindetail');
    }

    /**
     * 市场前景
     */
    public function prospect(){
        $data = Db::name('system')->find();
        $this->assign('data', $data['prospect']);
    	return $this->fetch(':prospect');
    }

    /**
     * 市场前景
     */
    public function advantage(){
        $data = Db::name('system')->find();
        $this->assign('data', $data['advantage']);
    	return $this->fetch(':advantage');
    }

    /**
     * 公司简介
     */
    public function company(){
        $data = Db::name('system')->find();
        $this->assign('data', $data['company']);
    	return $this->fetch(':company');
    }

    /**
     * 留言
     */
    public function message(){
        
        $MessageModel = new MessageModel();
        $post = $this->request->param();
        $result = $this->validate($post, 'Message');
        if ($result !== true) {
            $this->error($result);
        }

        $MessageModel->addMessage($post);
        $this->success('感谢你的宝贵建议');
        //return $this->fetch(':company');
    }

    /**
     * 新闻列表
     */
    public function news(){

        $result = Db::name('news')->where('status', 1)->order('update_time')->field('id,title,pic,update_time')->paginate(9);

        $this->assign('data', $result->items());
        $this->assign('page', $result->render());

        return $this->fetch(':news');
    }

    /**
     * 加盟详情
     */
    public function newsdetail(){
        $id = $this->request->param('id');
        $data = Db::name('news')->find($id);
        $this->assign('data', $data);
        return $this->fetch(':newsdetail');
    }
}
